﻿using System;
using System.Collections.Generic;

using NUnit.Framework;

using VidoopSecure;
using VidoopSecureExtensionMethods;

namespace TestVidoopSecure
{
    [TestFixture]
    public class TestVoicePinService : BaseTest
    {
        [TestFixtureSetUp]
        public override void SetUp()
        {
            base.SetUp();
        }

        [TestFixtureTearDown]
        public override void TearDown()
        {
            base.TearDown();
        }


        [Test]
        public void Test_GetService()
        {
            Service voicepinService = Manager.GetService(
                "voicepin", CurrentSite);
            Assert.IsNotNull(voicepinService);
        }

        [Test]
        public void Test_Newvoicepin()
        {
            VoicePinService service = (VoicePinService)Manager.GetService(
                "voicepin", CurrentSite);
            Assert.IsNotNull(service);

            Random rand = new Random(DateTime.Now.Millisecond);
            string userId = RandomString(8,false);
            string phone = Settings.PhoneNumber;
            string pin = RandomNumber(1000, 9999).ToString();
            VoicePin voicepin = service.NewVoicePin(userId, phone, pin);
            Assert.IsNotNull(voicepin);

            Assert.AreEqual(phone, voicepin.Phone);
            Assert.AreEqual("success", voicepin.SendStatus);
            Assert.AreEqual("pending", voicepin.AuthenticationStatus);

            // Test the GET of the transaction status
            VoicePin voicepin2 = service.GetVoicePin(voicepin.Id);
            Assert.IsNotNull(voicepin2);

            Assert.AreEqual(phone, voicepin2.Phone);
            //Result of this next test depends on whether you answered call I believe.
            //Assert.IsTrue("pending" == voicepin2.SendStatus ||
            //              "success" == voicepin2.SendStatus);
            Assert.AreEqual("pending", voicepin2.AuthenticationStatus);
       }
    }
}
